<template>
	<view class="page">
		<u-navbar title="品牌故事" is-fixed background="url('https://www.yplm888.com//uploads/20220803/7ed305f9a93ba50b049a7725662b18cc.png') no-repeat"></u-navbar>
		<view class="input">
			<my-input @search="search" :value='searchVaule'></my-input>
		</view>
		<scroll-view class="" :scroll-y="true" :style="'height:' + scrollH+'rpx;'" @scrolltolower="lowerBottom">
			<view class="list">
				<video-list :dataList='broandStory' :pageType="'broandStory'"></video-list>
			</view>
		</scroll-view>
	</view>
</template>

<script>
	import videoList from '../components/video-list.vue'
	export default {
		components: {
			videoList
		},
		data() {
			return {
				broandStory:[],
				searchValue:'',
				scrollH:0,
				page:1,
				triggered: false,
			}
		},
		onLoad() {
			this._freshing = false;
			this.initData()
		},
		onReady() {
			let that = this;
			uni.getSystemInfo({
				success: function(res) {
					that.scrollH = res.windowHeight * 750 / res.windowWidth;
					// #ifdef MP-WEIXIN
					that.scrollH = res.windowHeight * 750 / res.windowWidth - parseInt(res.safeArea.top) - 200;
					// #endif
				}
			});
		},
		onReachBottom() {
			this.page++
			this.initData()
		},
		methods: {
			initData() {
				let data = {
					page:this.page,
					limit:10,
					keyword: this.searchValue
				}
				// 获取品牌故事
				this.$u.api.BrandstoryList(data).then(res => {
					this.broandStory = [...this.broandStory,...res.data]
				})
			},
			search(value) {
				this.searchValue = value
				this.broandStory = []
				this.initData()
			},
			onPulling(e) {
				this.triggered = true;
			},
			async onRefresh() {
				if (this._freshing) return;
				this._freshing = true;
				this.page = 1;
				await setTimeout(() => {
					this.triggered = false;
					this._freshing = false;
					this.broandStory = []
					this.initData();
				}, 1000);
				uni.showToast({
					title: '刷新成功',
					duration: 1000
				})
			},
			onRestore() {
				this.triggered = false; // 需要重置
				console.log("onRestore");
			},
			onAbort() {
				console.log("onAbort");
			},
			// 触底加载
			lowerBottom() {
				this.page++;
				this.initData();
			}
		}
	}
</script>

<style lang="scss" scope>
	.page {
		padding: 20rpx 10rpx;
		position: relative;
		.input{
			// position: fixed;
			width: 100%;
			// top: 200rpx;
			// z-index: 66;
		}
		.list{
			margin: 20rpx;
		}
	}
</style>
